<template>
  <div>
    <h1>我是哥哥</h1>
    <p>{{count}}</p>
    <button @click="add">累加并发送数据</button>
    <button @click="byebye">取消订阅</button>
  </div>
</template>

<script>
import PubSub from "pubsub-js"
export default {
    name:"Gege",
    data(){
       return{
            count:0
       } 
    },
    methods:{
        add(){
            this.count++;
            //发布数据
            PubSub.publish("count",this.count)
        },
        byebye(){
      //unsubscribe参数如果是订阅名称,则直接取消当前名称的所有订阅

          PubSub.unsubscribe("count")
        }
    }
}
</script>

<style>

</style>